package org.csu.myPetStore.web.servlet.Order;

import org.csu.myPetStore.domain.Account;
import org.csu.myPetStore.domain.Order;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class OrderShippingDealServlet extends HttpServlet {

    private static final String CONFIRM_ORDER = "/WEB-INF/jsp/order/ConfirmOrder.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Order order = (Order) session.getAttribute("order");

        addOrder(order,req,resp);
        session.setAttribute("order",order);

        req.getRequestDispatcher(CONFIRM_ORDER).forward(req,resp);

    }

    protected void addOrder(Order order,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        order.setShipToFirstName(req.getParameter("order.shipToFirstName"));
        order.setShipToLastName(req.getParameter("order.shipToLastName"));
        order.setShipAddress1(req.getParameter("order.shipAddress1"));
        order.setShipAddress2(req.getParameter("order.shipAddress2"));
        order.setShipCity(req.getParameter("order.shipCity"));
        order.setShipState(req.getParameter("order.shipState"));
        order.setShipZip(req.getParameter("order.shipZip"));
        order.setShipCountry(req.getParameter("order.shipCountry"));
    }
}
